<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

$topdirectory="MSWebGUI";
include $topdirectory.'/FileList.php';

$topdirectory="Classes";
include $topdirectory.'/FileList.php';


$Action = "";
if(isset($_POST))
{
	if (isset($_POST['Action']))
	{
		$Action = $_POST['Action'];
	}
}

$xml = simplexml_load_file('config/config.xml');
$databaseXML = $xml->Database;
$database = new Database($databaseXML->Server,$databaseXML->Database,$databaseXML->Username,$databaseXML->Password);

//echo "Action=".$Action."<br>";;
switch($Action)
{
		case 'logoff':
	
			$sql="UPDATE UserSessions SET Expires = '2010-01-01 01:00:00' WHERE SessionID = '".$_POST['SessionID']."' AND Username = '".$_POST['User'];
			$database->ExecuteSql($sql);
			$thisPage = new CMRPage($database);
			break;
			
		case 'ShowSectionChoral':
			$thisPage = new CMRPageShowSection($database,"Choral");
			break;
					
		case 'ShowSectionOrgan':
			$thisPage = new CMRPageShowSection($database,"Organ");
			break;
					
		case 'ShowSectionLiturgy':
			$thisPage = new CMRPageShowSection($database,"Liturgy");
			break;
					
		case 'ShowSectionProfessional':
			$thisPage = new CMRPageShowSection($database,"Professional");
			break;
			
		case 'ShowChoralCategory':
			$thisPage = new CMRPageShowCategory($database,"Choral", $_POST['Category']);
			break;
			
		case 'ShowOrganCategory':
			$thisPage = new CMRPageShowCategory($database,"Organ", $_POST['Category']);
			break;
			
		case 'ShowLiturgyCategory':
			$thisPage = new CMRPageShowCategory($database,"Liturgy", $_POST['Category']);
			break;
			
		case 'ShowProfessionalCategory':
			$thisPage = new CMRPageShowCategory($database,"Professional", $_POST['Category']);
			break;
			
		case 'ShowSearch':
			$thisPage = new CMRPageShowSearch($database,"Professional");
			break;
			
		case 'ShowResource':
			$thisPage = new CMRPageShowResource($database,$_POST['ResourceID']);
			break;

		case 'adminCreateResource':
		case 'InsertRecord':
			$thisPage = new CMRPageCreateResource($database);
			break;
			
		case 'adminEditResource':
		case 'UpdateRecord':
			$thisPage = new CMRPageEditResource($database);
			break;
			
		case 'adminSubmitResource':
			$thisPage = new CMRPageSubmitResource($database);
			break;
			
		case 'adminApproveResource':
			$thisPage = new CMRPageApproveResource($database);
			break;
			
/*		case 'adminEditResource':
			$thisPage = new CMRPageViewHistoryResource($database);
			break;
*/			
		case 'adminTest':
			$thisPage = new CMRPageTest($database);
			break;
			
		case 'adminSessionHistory':
			$thisPage = new CMRPageSessionHistory($database);
			break;
			
		default:
			
			$thisPage = new CMRPage($database);
			break;
}	
				

//$thisPage->setDatabase($database);


echo $thisPage->getHTML();
	
?>